/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gerarformularios;

import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.ExceptionConverter;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;

/**
 *
 * @author pedro
 */
class HeaderFooter extends PdfPageEventHelper {

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        try {
            Rectangle page = document.getPageSize();
            /* 
             * PdfPTable head = new PdfPTable(3); for (int k = 1; k <= 6; ++k) 
             * head.addCell("head " + k); head.setTotalWidth(page.getWidth() - 
             * document.leftMargin() - document.rightMargin()); 
             * head.writeSelectedRows(0, -1, document.leftMargin(), 
             * page.getHeight() - document.topMargin() + head.getTotalHeight(), 
             * writer.getDirectContent()); 
             */
            PdfPTable foot = new PdfPTable(1);
            Image image = Image.getInstance("C:/Users/pedro/Documents/NetBeansProjects/GerarFormularios/build/classes/gerarformularios/facom.jpg");
            PdfPCell cell = new PdfPCell(image);
            cell.setBorder(0);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            foot.addCell(cell);

            foot.setTotalWidth(page.getWidth() - document.leftMargin()
                    - document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent());

        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }

    }
}
